<template>
  <div>
    <el-dialog width="70%" :visible.sync="formShow" @close="handleClickDeal('cancel')" v-dialog-drag  :modal-append-to-body="false" :close-on-click-modal="false">
      <span slot="title">
        <i class="iconfont icon-rizhi"></i>
        <span>{{title}}</span>
      </span>
      <div class="WholeScroll" style="max-height: 65vh;overflow-y: auto;overflow-x: hidden"
           v-loading="isLoading"
           element-loading-text="电子日志生成中，请稍后..."
           element-loading-spinner="el-icon-loading"
           element-loading-background="rgba(0, 0, 0, 0.8)">
        <el-form :model="formBaseData" ref="formBaseData" :rules="formBaseRules" class="measurepaycompensation_detail_form">
          <el-row>
                               <el-col :span="12">
                                 <el-form-item label="公司" prop="companyId" :label-width="formlabelWidth">
                                   <el-select
                                     style="margin: 0; margin-right: 15px;width: 100%"
                                     class="select"
                                     size="small"
                                     v-model="formBaseData.companyId"
                                     :disabled="detailType === 'check'||detailType === 'approve'||detailType==='deal'||detailType==='stamp'"
                                     v-on:change="getProjectByCompanyId()"
                                     value-key="id"
                                     placeholder="选择公司"
                                     clearable
                                   >
                                     <el-option
                                       v-for="item in companyTree"
                                       :key="item.id"
                                       :label="item.name"
                                       :value="item.id"
                                     >
                                     </el-option>
                                   </el-select>
                                 </el-form-item>
                               </el-col>
            <el-col :span="12">
              <el-form-item label="项目" prop="projectId" :label-width="formlabelWidth">
                <el-select
                  style="margin: 0; margin-right: 15px;width: 100%"
                  class="select"
                  size="small"
                  v-model="formBaseData.projectId"
                  :disabled="detailType === 'check'||detailType === 'approve'||detailType==='deal'||detailType==='stamp'"
                  v-on:change="getContractByProjectId()"
                  value-key="id"
                  filterable
                  placeholder="选择项目"
                  clearable
                >
                  <el-option
                    v-for="item in projectTree"
                    :key="item.id"
                    :label="item.name"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item label="合同段" prop="contractId" :label-width="formlabelWidth">
                <el-select
                  style="margin: 0; margin-right: 15px;width: 100%"
                  class="select"
                  size="small"
                  @change="changeSectionInfo()"
                  v-model="formBaseData.contractId"
                  :disabled="detailType === 'check'||detailType === 'approve'||detailType==='deal'||detailType==='stamp'"
                  placeholder="选择合同段"
                  clearable
                >
                  <el-option
                    v-for="item in contractTree"
                    :key="item.id"
                    :label="item.numberName"
                    :value="item.id"
                  >
                  </el-option>
                </el-select>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item class="" label="模板名称" prop="templateName" :label-width="formlabelWidth">
                <el-input size="small" v-model="formBaseData.templateName" placeholder=""
                          :disabled="true"></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item class="" label="旁站日期" prop="logDate"
                            :label-width="formlabelWidth">
                <el-date-picker
                  v-model="formBaseData.logDate"
                  type="date"
                  :picker-options="pickerOptions0"
                  style="width:100%"
                  format='yyyy-MM-dd'
                  value-format='yyyy-MM-dd'
                  placeholder="选择日期"
                  :disabled="detailType === 'check' || detailType === 'approve'">
                </el-date-picker>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item class="" label="编号" prop="logNumber" :label-width="formlabelWidth">
                <el-input size="small" v-model="formBaseData.logNumber"  placeholder=""
                          :disabled="detailType === 'check'|| detailType === 'approve' "></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item class="whole-line" label="旁站人" prop="supervisorUser" :label-width="formlabelWidth">
                <el-input size="small" v-model="formBaseData.supervisorUser"  placeholder=""
                          :disabled="detailType === 'check'|| detailType === 'approve' "></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col :span="12">
              <el-form-item class="" label="工程项目" prop="engineeringName" :label-width="formlabelWidth">
                <el-input size="small" v-model="formBaseData.engineeringName" placeholder="填写工程名称"
                          :disabled="detailType === 'check'|| detailType === 'approve' "></el-input>
              </el-form-item>
            </el-col>
            <el-col :span="12">
              <el-form-item class="" label="填报单位" prop="fillUnit" :label-width="formlabelWidth">
                <el-input size="small" v-model="formBaseData.fillUnit"  placeholder=""
                          disabled></el-input>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row>
            <el-col :span="12">

              <el-form-item class="" label="施工单位" prop="constrCompanyName" :label-width="formlabelWidth">
                <el-input size="small" v-model="formBaseData.constrCompanyName"
                          :disabled="true "></el-input>
              </el-form-item>
            </el-col>
          </el-row>
          <!--                  <el-row>-->
          <!--                    <el-col :span="12">-->
          <!--                      <el-form-item class="" label="质检人员" prop="qualityInspector" :label-width="formlabelWidth">-->
          <!--                        <el-input size="small" :disabled="detailType === 'check'|| detailType === 'approve' "  v-model="formBaseData.qualityInspector"  placeholder=""></el-input>-->
          <!--                      </el-form-item>-->
          <!--                    </el-col>-->
          <!--                    <el-col :span="12">-->
          <!--                      <el-form-item class="" label="部位或桩号" prop="position" :label-width="formlabelWidth">-->
          <!--                        <el-input size="small" v-model="formBaseData.position"  placeholder=""-->
          <!--                                  :disabled="detailType === 'check'|| detailType === 'approve' "></el-input>-->
          <!--                      </el-form-item>-->
          <!--                    </el-col>-->
          <!--                  </el-row>-->
          <el-row>
            <el-col :span="24">
              <el-form-item prop="sideStationProject" label="旁站项目" :label-width="formlabelWidth">
                <el-input
                  class="fill"
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 6}"
                  placeholder="旁站项目"
                  v-model="formBaseData.sideStationProject"
                  :disabled="detailType === 'check'|| detailType === 'approve' "
                >
                </el-input>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="constructionProcess" label="施工过程简述" :label-width="formlabelWidth">
                <el-input
                  class="fill"
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 6}"
                  placeholder="施工过程简述"
                  v-model="formBaseData.constructionProcess"
                  :disabled="detailType === 'check'|| detailType === 'approve' "
                >
                </el-input>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="onSiteWork" label="旁站工作情况" :label-width="formlabelWidth">
                <el-input
                  class="fill"
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 6}"
                  placeholder="旁站工作情况"
                  v-model="formBaseData.onSiteWork"
                  :disabled="detailType === 'check'|| detailType === 'approve' "
                >
                </el-input>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="dataRecord" label="主要数据记录" :label-width="formlabelWidth">
                <el-input
                  class="fill"
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 6}"
                  placeholder="主要数据记录"
                  v-model="formBaseData.dataRecord"
                  :disabled="detailType === 'check'|| detailType === 'approve' "
                >
                </el-input>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row>
            <el-col :span="24">
              <el-form-item prop="result" label="发现的问题及处理结果" :label-width="formlabelWidth">
                <el-input
                  class="fill"
                  type="textarea"
                  :autosize="{ minRows: 4, maxRows: 6}"
                  placeholder="发现的问题及处理结果"
                  v-model="formBaseData.result"
                  :disabled="detailType === 'check'|| detailType === 'approve' "
                >
                </el-input>
              </el-form-item>
            </el-col>

          </el-row>
          <el-row>
            <el-col :span="19" style="position: relative">
              <el-form-item label="现场照片" :label-width="formlabelWidth">
                <cmsUploadFileJpg
                  ref="fileThree"
                  :detail-id="detailId"
                  :fileSystem="fileSystem['three']"
                  :disabled="detailType === 'check'|| detailType === 'approve'"
                  type="mul"
                  :fileList="fileListThree"
                  info="支持上传 png/jpg/gif 文件"
                  :detail-type="detailType" />
              </el-form-item>
            </el-col>
          </el-row>
          <el-row>
            <el-col  :span="19"  style="position: relative" class="otherMeterageUpload">
              <el-form-item label="附件" :label-width="formlabelWidth">
                <cmsUploadFile
                  ref="fileOne"
                  :detail-id="detailId"
                  :fileSystem="fileSystem['one']"
                  :disabled="detailType === 'check'|| detailType === 'approve'"
                  type="mul"
                  :fileList="fileList"
                  info="支持上传 png/jpg/gif/doc/xlsx/ppt/pdf等文件"
                  :detail-type="detailType" />
              </el-form-item>

            </el-col>
          </el-row>
        </el-form>
      </div>
      <div slot="footer" class="dialog-footer">
        <!--api操作按钮 除去上报-->
        <!--新建和编辑的暂存上报-->
        <template v-if="detailType === 'build' || detailType === 'edit'">
          <el-button size="small" type="primary" :loading="isLoading" @click="handleClickDeal('createFile', {flag: 1})">
            <i class="iconfont icon-icon_save"></i> 确 定</el-button>
          <!--     <el-button size="small" type="primary" :loaidng="isLoading" @click="handleClickDeal('submit', {flag: 1})"><i class="iconfont icon-icon_save"></i> 确 定</el-button>-->
        </template>
        <el-button size="small" @click="handleClickDeal('cancel')"><i class="iconfont icon-icon_cancel"></i> 取 消</el-button>
      </div>
    </el-dialog>
  </div>
</template>

<script>
  import projectSectionInfo from "@/api/buss/common";
  import sectionInfo from "@/api/buss/sectionInfo";
  import dept from "@/api/system/dept";
  import msgUtil from "@/utils/msgUtil";
  import supervisionSideStation from "@/api/buss/supervisionSideStation";
  import supervisorlog from "@/api/buss/supervisorlog";
  import store from "@/store";
  import file from "@/api/file";
  import { Base64 } from 'js-base64'
  export default {
    name: "supervisionSideStation-detail",
    props: {
      postDetail: {
        type: Object,
        default: {
          show: false,
          type: 'build',
          params: {}
        }
      }
    },
    watch: {
      postDetail(value) {
        // 显示详情弹窗
        this.formShow = value.show
        // 初始化窗口参数
        this.activeName = 'first'
        // 详情类型
        this.detailType = value.type
        if (this.detailType == 'build') {
          this.title = '新增监理旁站记录'
          this.formBaseData.supervisorUser = store.getters.user.name
          this.isShowBpmn=true
        } else if (this.detailType == 'check') {
          this.title = '查看监理旁站记录'
        } else if (this.detailType == 'edit') {
          this.isShowBpmn=true
          this.title = '编辑监理旁站记录'
        }else if (this.detailType == 'approve') {
          this.isShowBpmn=true
          this.title = '监理旁站记录审核'
        }else {
          this.title = ''
        }

        // 详情id
        this.detailId = value.detailId?value.detailId:'';
        // 非新建详情时 获取详情
        if (this.detailType == 'build') {
          this.getFillUnit()
          this.$nextTick(()=>{
            this.$refs['formBaseData'].resetFields()
            this.initData()
          })
        } else {
          // 获取详情请求
          this.initData().then(res=>{
            this.getDetail()
          })
        }
      }
    },
    data() {
      return {
        pickerOptions0: {
          disabledDate(time) {
            return time.getTime() > Date.now() - 8.64e6
          }
        },
        startDatePicker: this.beginDate(),
        endDatePicker: this.processDate(),
        fileList: [],
        fileListThree: [],
        companyTree: [], // 公司下拉
        projectTree: [], // 项目下拉
        contractTree: [], // 合同段下拉
        checkInitShow:false,
        isLoading:false,
        actionType: '查看',
        title: '监理旁站记录',
        isYz:false,//上报人公司类型 是否是业主
        //存放图片的数组
        fileListArray: [],
        detailType: 'build', // 详情类型 build新建 check不可编辑查看 edit编辑
        detailId: '', // 当前详情的id
        activeName: 'first', //
        detailActions: [], // 当前详情的操作项
        formShow: false, // 表单展示
        radioValue:'',//单选按钮选中的值
        formlabelWidth: '110px', // 表单左侧标题宽度
        selectList: {
          file: [], // 文件
          approver: [], // 审批人
          structureType: [], // 结构类型
        },
        fileSystem: {
          'one': {
            sys: 'buss',
            module: 'supervisionSideStation',
            part: 'one',
            compoName: 'fileOne'
          },
          'three': {
            sys: 'buss',
            module: 'supervisionSideStation',
            part: 'three',
            compoName: 'fileThree'
          }
        }, // 文件系统的参数
        // 所有下拉框列表的集合
        // 表单基本信息内容
        formBaseData: {
          companyId:'',
          contractId:'',
          projectId:'',
          constrCompany:'',//施工单位
          constrCompanyName:'',//施工单位
          supervisorCompany:'',//监理单位
          supervisorCompanyName:'',//监理单位
          logNumber:'',//日志编号
          logDate:new Date().Format("yyyy-MM-dd"),//施工日志日期
          startDate:'',
          endDate:'',
          contractName:'',
          supervisorUser:'',//记录人
          constrRemark:'',//备注
          qualityInspector:'',
          position:'',
          log: [], // 日志
          isCreateFile:'',
          templateName:'监理日志（JTGG10-2016）',
          engineeringName:'',
          sideStationProject:'',
          constructionProcess:'',
          onSiteWork:'',
          dataRecord:'',
          result:'',
        },

        // 表单基本信息验证
        formBaseRules: {
          companyId: [
            {required: true, message: '请选择' + '公司', trigger: 'change'},
          ],
          projectId: [
            {required: true, message: '请选择' + '项目', trigger: 'change'},
          ],
          contractId: [
            {required: true, message: '请选择' + '合同段', trigger: 'change'},
          ],
          logDate: [
            {required: true, message:'请输入'+'旁站日期' , trigger: 'blur'},
          ],
          logNumber: [
            {required: true, message: '请输入' + '编号', trigger: 'change'},
          ],
          startDate: [
            {required: true, message:'请输入'+'到场时间' , trigger: 'blur'},
          ],
          endDate: [
            {required: true, message:'请输入'+'离场时间' , trigger: 'blur'},
          ],
          supervisorUser: [
            {required: true, message:'请输入'+'旁站监理' , trigger: 'blur'},
          ],

          engineeringName: [
            {required: true, message: '请输入' + '工程项目', trigger: 'change'},
          ],
          sideStationProject: [
            {required: true, message:'请输入'+'旁站项目' , trigger: 'blur'},
          ],
        },

      }
    },
    created () {
    },
    methods: {
      openFile () {
        supervisionSideStation.getOne(this.detailId).then(res => {
          if (res.code == 200) {
            let fileId = res.data.fileId
            this.viewFile(fileId)
          }else {
            msgUtil.error2(res.data.message)
          }
        }).catch(() => {
          msgUtil.error2("打开文件失败")
        })
      },
      viewFile(e) {
        this.isLoading = true
        file.preview(e).then(response => {
          //  如果是minio地址路径，则调用kkview
          if(!response.data.startsWith("/")) {
            window.open(PREVIEW_URL + '/onlinePreview?url=' + encodeURIComponent(Base64.encode(response.data)));
          }else{
            //  如果是转换后的previewGetFile，浏览器直接打开
            window.open(response.data);
          }
          this.isLoading = false
        })
      },
      getFillUnit(){
        supervisionSideStation.getFillUnit({}).then(res => {
          if (res.code === 200) {
            var data = res.data;
            this.formBaseData.fillUnit=data
          }else {
            msgUtil.error2(res.data.message)
          }
        }).catch(() => {
          msgUtil.error2("获取填报单位失败")
        })
      },
      //约束选择日期的范围
      beginDate() {
        const self = this
        return {
          disabledDate(time) {
            if (self.formBaseData.endDate) {
              //如果结束时间不为空，则小于结束时间
              return (
                new Date(self.formBaseData.endDate).getTime() < time.getTime()
              )
            } else {
              // return time.getTime() > Date.now()//开始时间不选时，结束时间最大值小于等于当天
            }
          }
        }
      },
      processDate() {
        const self = this
        return {
          disabledDate(time) {
            if (self.formBaseData.startDate) {
              //如果开始时间不为空，则结束时间大于开始时间
              return (
                new Date(self.formBaseData.startDate).getTime() > time.getTime()
              )
            } else {
              // return time.getTime() > Date.now()//开始时间不选时，结束时间最大值小于等于当天
            }
          }
        }
      },
      changeSectionInfo(){
        let id=''
        let coalition = ''
        this.contractTree.forEach(item=>{
          if(item.id==this.formBaseData.contractId){
            id=item.secondParty
            coalition = item.coalition
            this.formBaseData.contractName=item.numberName
          }
        })
        var ids=id.split(",")
        this.formBaseData.supervisorCompanyName=''
        this.formBaseData.supervisorCompany=''
        if(coalition == 1){  //非联合体
          dept.getOne(ids[0]).then(res => {
            if (res.code === 200) {
              var data = res.data;
              this.formBaseData.supervisorCompanyName=data.simplename
              this.formBaseData.supervisorCompany=data.id
            }else {
              msgUtil.error2(res.data.message)
            }
          }).catch(() => {
            msgUtil.error2("获取合同段相关单位失败")
          })
        } else {
          supervisorlog.getCompanyByContractId(this.formBaseData.contractId).then(res => {
            if (res.code === 200) {
              var data = res.data;
              this.formBaseData.supervisorCompanyName=data.supervisorUnit
              this.formBaseData.supervisorCompany=data.supervisorUnitId
            }else {
              msgUtil.error2(res.data.message)
            }
          }).catch(() => {
            msgUtil.error2("获取合同段相关单位失败")
          })
        }
        supervisorlog.buildUnit(this.formBaseData.contractId).then(res => {
          if (res.code === 200) {
            var data = res.data;
            this.formBaseData.constrCompanyName=data.buildName

          }else {
            msgUtil.error2(res.data.message)
          }
        }).catch(() => {
          msgUtil.error2("获取合同段施工单位失败")
        })
        if (this.detailType ==='build'){
          this.getLogNumber()
        }
      },
      initData(){
        this.companyTree = []

        return   projectSectionInfo.getProjectSectionInfoTree().then(res => {
          if (res.code === 200) {
            var data = res.data;
            this.companyTree = data
            if(this.detailType=='build' && this.companyTree.length>0){
              this.formBaseData.companyId = this.companyTree[0].id;
              this.getProjectByCompanyId()
            }
            return new Promise(resolve => {
              resolve(res)
            })
          }else {
            msgUtil.error2(res.data.message)
          }
        }).catch(() => {
          msgUtil.error2("获取项目标段树失败")
        })

      },

      getLogNumber(){
        let sectionId = this.formBaseData.contractId
        this.$httpGet('buss/commonAPI/getLogNumber?type=7&sectionId='+sectionId).then(res => {
          if (res.code === 200) {
            this.formBaseData.logNumber = res.data
          }else {
            msgUtil.error2(res.data.message)
          }
        }).catch((res) => {
        })
      },
      /**
       *  根据建设单位查询下面的所有项目
       * */
      getProjectByCompanyId() {
        if(this.formBaseData.projectId&&!this.checkInitShow){
          this.formBaseData.projectId = ''
        }
        if(this.formBaseData.contractId&&!this.checkInitShow){
          this.formBaseData.contractId = ''
        }

        this.companyTree.forEach((item) => {
          if (item.id === this.formBaseData.companyId) {
            this.projectTree = item.children
            if(this.detailType =='build' && this.projectTree.length>0){
              this.formBaseData.projectId = this.projectTree[0].id;
              this.getContractByProjectId();
            }
          }
        })
      },

      /**
       * 根据项目id获取监理合同段列表
       * getContractByProjectId
       * */
      getContractByProjectId() {

        if(this.formBaseData.contractId&&!this.checkInitShow){
          this.formBaseData.contractId = ''
        }

        if(this.checkInitShow){
          this.checkInitShow=false
        }
        console.log(this.formBaseData.projectId,'this.formBaseData.projectId');

        if (this.formBaseData.projectId) {
          console.log( 1111,' this.contractTree');
          projectSectionInfo.getContractList({projectId:this.formBaseData.projectId}).then(res => {
            if (res.code === 200) {
              this.contractTree = res.data;

              if(this.detailType =='build' && this.contractTree.length>0){
                this.formBaseData.contractId = this.contractTree[0].id;
                this.getLogNumber()
                this.changeSectionInfo();
              }
            }else {
              msgUtil.error2(res.data.message)
            }
          }).catch(() => {
            msgUtil.error2("获取监理合同段失败")
          })
        }
      },

      // 获取详情请求 api
      getDetail () {
        supervisionSideStation.getOne(this.detailId).then(res => {
          if (res.code == 200) {
            this.formBaseData=res.data
            this.checkInitShow=true
            this.getProjectByCompanyId()
            this.getContractByProjectId()
            this.changeSectionInfo()
            this.loadFiles()
          }else {
            msgUtil.error2(res.data.message)
          }
        }).catch(() => {
          msgUtil.error2("获取详情信息失败")
        })
      },
// 提交详情 提交1/暂存0 新建0/修改1
      submitAndCreateDetail (type, callback,slient) {
        this.formBaseData.isCreateFile = '1'
        let param = JSON.parse(JSON.stringify(this.formBaseData))
        if (this.detailType === 'build') {
          this.isLoading=true
          supervisionSideStation.submit(param).then(res => {
            if (res.code === 200) {
              this.formShow = false
              this.detailId = res.data.id
              // this.openFile()
              if (callback) callback()
            }else {

              msgUtil.error2(res.data.message)
            }
          }).catch((res) => {
            console.log(res)
            // this.$notify({
            //   title: '施工安全日志保存失败',
            //   type: 'error',
            //   duration: 2500
            // })
          }).finally((response) => {
            this.isLoading = false
          })
        }else{
          this.isLoading=true
          supervisionSideStation.resubmit(param).then(res => {
            if (res.code === 200) {
              this.formShow = false
              this.detailId = res.data.id
              // this.openFile()
              if (callback) callback()
            }else {
              msgUtil.error2(res.data.message)
            }
          }).catch((res) => {
            console.log(res)
            // this.$notify({
            //   title: '施工安全日志保存失败',
            //   type: 'error',
            //   duration: 2500
            // })
          }).finally((response) => {
            this.isLoading = false
          })
        }
      },
      // 提交详情 提交1/暂存0 新建0/修改1
      submitDetail (type, callback,slient) {
        if (this.detailType === 'build') {
          this.isLoading=true
          let param = JSON.parse(JSON.stringify(this.formBaseData))
          supervisionSideStation.submit(param).then(res => {
            if (res.code === 200) {
              this.formShow = false
              this.detailId = res.data.id
              if (callback) callback()
            }else {
              msgUtil.error2(res.data.message)
            }
          }).catch((res) => {
            console.log(res)
            // this.$notify({
            //   title: '监理旁站记录保存失败',
            //   type: 'error',
            //   duration: 2500
            // })
          }).finally((response) => {
            this.isLoading = false
          })
        }else{
          this.isLoading=true
          supervisionSideStation.resubmit(this.formBaseData).then(res => {
            if (res.code === 200) {
              this.formShow = false
              this.detailId = res.data.id
              if (callback) callback()
            }else {
              msgUtil.error2(res.data.message)
            }
          }).catch((res) => {
            console.log(res)
            // this.$notify({
            //   title: '监理旁站记录保存失败',
            //   type: 'error',
            //   duration: 2500
            // })
          }).finally((response) => {
            this.isLoading = false
          })
        }
      },
      // 事件处理的api请求
      sealDealHttp (url, query, params, callback) {
        this.$httpPost(
          this.$store.state.httpHost.buss + url + query,
          params
        ).then(res => {
          if (res.data.status === 1) {
            if (callback) callback(res.data)
          } else {
            this.$messageError(res.data.message)
          }
        }).catch(res => {
          console.log(res)
        })
      },
      // 点击各个流程的按钮事件
      handleClickDeal (type, res) {
        console.log(type, res)
        switch (type) {
          // 取消，关闭窗口
          case 'cancel':
            // 重置表单验证
            this.$refs['formBaseData'].resetFields()
            // 清空表单内容
            this.formBaseData = {
              companyId:'',
              contractId:'',
              projectId:'',
              constrCompany:'',//施工单位
              constrCompanyName:'',//施工单位
              supervisorCompany:'',//监理单位
              supervisorCompanyName:'',//监理单位
              logNumber:'',//日志编号
              logDate:new Date(),//施工日志日期
              startDate:'',
              endDate:'',
              contractName:'',
              supervisorUser:'',//记录人
              constrRemark:'',//备注
              qualityInspector:'',
              position:'',
              log: [], // 日志
              isCreateFile:'',
              templateName:'监理日志（JTGG10-2016）',
              engineeringName:'',
              sideStationProject:'',
              constructionProcess:'',
              onSiteWork:'',
              dataRecord:'',
              result:'',

            } // 表单基本信息内容
            // 清空文件
            this.fileList = []
            this.fileListThree = []

            for (let k in this.fileSystem) {
              let fileProp = this.fileSystem[k]
              this.$refs[fileProp.compoName].cancelAll()
            }
            // 关闭弹窗
            this.formShow = false
            break
          // 保存
          case 'submit':
            let flag = res.flag
            // 表单验证
            this.$refs['formBaseData'].validate((valid) => {
              if (valid) {
                // 提交详情
                this.submitDetail(flag, () => {
                  this.saveFiles()
                  setTimeout(() => {
                    this.$emit('reloadList')
                    this.$notify({
                      title: '监理旁站记录保存成功',
                      type: 'success',
                      duration: 1500
                    })
                  }, 1500)

                },true)
              }
            });
            break
          case 'createFile':
            // 表单验证
            this.$refs['formBaseData'].validate((valid) => {
              if (valid) {

                // 提交详情
                this.submitAndCreateDetail(flag, () => {
                  this.saveFiles()
                  setTimeout(() => {
                    this.$emit('reloadList')
                    this.$notify({
                      title: '监理旁站记录保存成功',
                      type: 'success',
                      duration: 1500
                    })
                  }, 1500)
                },true)
              }
            });
            break
          // 删除
          case 'delete':
            break
        }
      },
      saveFiles() {
        for (let k in this.fileSystem) {
          let fileProp = this.fileSystem[k]
          this.$refs[fileProp.compoName].saveAll(this.detailId)
        }
      },

      loadFiles() {
        this.$nextTick(()=>{
          for (let k in this.fileSystem) {
            let fileProp = this.fileSystem[k]
            this.$refs[fileProp.compoName].init()
          }
        })
      },

    },
  }
</script>

<style scoped lang="scss">
  .el-select.half{
    width: 250px;
  }
  .el-select.fill{
    width: 800px;
  }

  .el-input .el-select{
    width: 130px;
  }
  .fee_add{
    color: #008fe0; border-color: #008fe0; float: right; margin-bottom: 10px;
  }
</style>
